// monitorLeave.js
export function monitorPageLeave() {
  let leaveTime = null
  const THIRTY_MINUTES = 30 * 60 * 1000 // 30分钟的毫秒数

  const handleVisibilityChange = () => {
    if (document.visibilityState === 'hidden') {
      // 用户离开页面，记录离开时间
      leaveTime = Date.now()
    } else if (document.visibilityState === 'visible') {
      // 用户返回页面
      if (leaveTime && Date.now() - leaveTime > THIRTY_MINUTES) {
        // 如果离开时间超过半小时，刷新页面
        location.reload()
      }
    }
  }

  document.addEventListener('visibilitychange', handleVisibilityChange)
}
